<?php
$this->breadcrumbs=array(
	'Articles'=>array('index'),
	$model->arc_id=>array('view','id'=>$model->arc_id),
	'Update',
);

$this->menu=array(
	array('label'=>'List Article', 'url'=>array('index')),
	array('label'=>'Create Article', 'url'=>array('create')),
	array('label'=>'View Article', 'url'=>array('view', 'id'=>$model->arc_id)),
	array('label'=>'Manage Article', 'url'=>array('admin')),
);
?>
<?php 

 	$add_category_url = $this->createUrl('category/createremote');
 	$add_category_type = Category::CATEGORY_NEWS;
 	
	$ready = <<<READY
//	var str = "这里填写文章标题";
//	$("#Article_arc_title").val(str).focus(function(){
//		if($(this).val()==str){
//			$(this).val("");
//		}		
//	});

	$(".category input[type=checkbox]").change(function(){
//		alert($(this).val());
		var str = "";
		$(".category input[type=checkbox]").each(function(){
			if($(this).attr("checked") == true){
				str += ","+$(this).val();
			}
		});

		str = str.substring(1,str.length);
		$("#Article_arc_cids").val(str);
		
//		alert(str);

	});

	$("#arc_submit").button();
	$("#get_tag").button();
	$("#add_category").button();
	
	$("#add_category").click(function(){
		$.post("$add_category_url",{
			'cate_pid':$("#Article_arc_cids").val(),
			'cate_name':$("#categoryName").val(),
			'cate_type':$add_category_type
		},function(msg){
//			alert(msg);
			$(".category").append(msg);
		});
	});
READY;

$analysis_url = $this->createUrl('analysis');
$head_js = <<<HEAD
	function showNext(object){
		object.next().slideToggle("slow");
		return false;
	}
	function getTag(){
	//	alert("Hello");
	//	content = $(document.getElementsByTagName('iframe')[0].contentWindow.document.body).html();
	//	content = $("#el-rte-editor").contents().find("body").html();
	//	content = $(document.getElementsByTagName('iframe')[0]).contents().find("body").html();
		content = $("#Article_arc_content").val();
//		alert(content);
		
		$.post('$analysis_url',{'content':content},function(msg){
			$("#Article_arc_tags").val(msg);
//			alert(msg);
		});
	}
HEAD;
?>

<?php Yii::app()->getClientScript()->registerScript('news-admin-create-ready',$ready,CClientScript::POS_READY);?>
<?php Yii::app()->getClientScript()->registerScript('news-admin-create-heade',$head_js,CClientScript::POS_HEAD);?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'article-form',
	'enableAjaxValidation'=>true,
)); ?>
<div class="column1" style="width:68%;">
	<div class="box">
	<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>CHtml::image($this->module->registerImage('article.png'),'Logo', array('width'=>'40')).'&nbsp;&nbsp;更新文章'));?>
		<div class="box-content">
			<?php echo Yii::t('admin','<p class="note">Fields with <span class="required">*</span> are required.</p>');?>	
	
			<?php echo $form->errorSummary($model); ?>
		
		
			<?php echo $this->renderPartial('_form', array('model'=>$model,'form'=>$form)); ?>		
		</div>
	<?php $this->endWidget();?>
	</div>
		
</div>
<div class="column2 form" style="margin-left:70%;width:29%;">
	<div class="box">
	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Publish',
		));
	?>
	<div class="box-content">
    	<div class="row">
    		<?php echo Yii::t('article','State')?>*：&nbsp;&nbsp;<span id="statelabel">PUBLIISHED</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_state',Article::model()->generateStateDropdownList(),array(
    					'style'=>'width:50%;'
    			)); ?>
    			<?php echo $form->error($model,'arc_state'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		<?php echo Yii::t('article','Comment')?>*：&nbsp;&nbsp;<span id="commentlabel">Allow</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_iscomment',Article::model()->generateCommentStateDropdownList(),array(
    					'style'=>'width:50%;'
    			)); ?>
    			<?php echo $form->error($model,'arc_iscomment'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		<?php echo Yii::t('article','Recommend');?>*：&nbsp;&nbsp;<span id="recommendlabel">Allow</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">				
    			<?php echo $form->dropDownList($model,'arc_isrecommend',Article::model()->generateRecommendStateDropdownList(),array(
    					'style'=>'width:50%;'
    			)); ?>
    			<?php echo $form->error($model,'arc_isrecommend'); ?>
    		</div>		
    	</div>
    	<div class="row">
    		<?php echo Yii::t('article','Time');?>*：&nbsp;&nbsp;<span id="timelabel"><?php echo date('Y-m-d H:i:s',time());?></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">修改</a>
    		<div class="hide">
    			<?php echo $form->textField($model,'arc_created',array('value'=>date('Y-m-d H:i:s',time()))); ?>
    			<?php echo $form->error($model,'arc_created'); ?>		
    		</div>
    
    	</div>
    </div>
	<?php 
		$this->endWidget();
	?>


	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'',
		));
	?>	<div class="box-content">
		<?php if($model->isNewRecord):?>
				<button type="submit" id="arc_submit" class="right" >Create</button> 
			<?php else:?>
				<button type="submit" id="arc_submit" class="right" >Update</button> 
		<?php endif;?>	
		</div>	
	<?php $this->endWidget();?>


	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Tags',
		));
	?>	
		<div class="box-content">
			<div class="row">
				<?php echo $form->textField($model,'arc_tags',array('style'=>'width:60%;')); ?>
				<button type="button" id="get_tag" class="right" onclick="getTag();" >Tags</button> 
				<?php echo $form->error($model,'arc_tags'); ?>
			</div>		
		</div>	
	<?php $this->endWidget();?>	

	<?php
		$this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Category',
		));
	?>
		<div class="box-content">
			<div class="row">
				<?php 
					$this->widget('application.components.category.CategoryList',array('view'=>'arclist','type'=>Category::CATEGORY_NEWS,'model'=>$model));
				?>
				&nbsp;&nbsp;<span id="categorylabel">PUBLIISHED</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void();" onclick="showNext($(this));">增加分类</a>
				<div class="hide">	
					<input type="hidden" id="Article_arc_cids" name="Article[arc_cids]" value="<?php echo $model->arc_cid;?>"/>	
					<input type="text" id="categoryName" name="categoryName" style="width:60%;" />	<button id="add_category" type="button">Add</button>	
					<?php echo $form->dropDownList($model,'arc_cid',Category::model()->getCategoryDropdownList(Category::CATEGORY_NEWS)); ?>
					<?php echo $form->error($model,'arc_cid'); ?>
				</div>	
			</div>		
		</div>
	
	<?php $this->endWidget();?>
	</div>
</div>
<?php $this->endWidget(); ?>